using System;
using System.Collections.Generic;
using Mall.Api.Entity;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using Mall.Api.ParamModel;
using Newtonsoft.Json;
using Mall.Api.Repository;
using Mall.Api.Utils;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Authorization;
using Mall.Api.Filters;


namespace Mall.Api.Controllers
{
    /// <summary>
    /// 修改图片
    /// </summary>


    // [Authorize]

    [ApiController]
    [Route("aaaa")]
    public class AmendController : ControllerBase
    {
     
        private IRepository<Commodity> _commodity;
     

        private readonly IConfiguration _configuration;

        public AmendController(IConfiguration configuration, IRepository<Class> classes, IRepository<Brand> brand,
        IRepository<Commodity> commodity, IRepository<Supplier> supplier)
        {
            _configuration = configuration;
           
            _commodity = commodity;
          

        }



          /// <summary>
        /// 修改商品信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="model"></param>
        /// <returns></returns>

        [HttpPut("{id}")]
        public dynamic Put(int id, AmendCommodity model)
        {
            var commodity = _commodity.GetById(id);


            if (commodity != null)
            {
                commodity.Introduction=model.Introduction;
                commodity.CoverPicture=model.CoverPicture;


                commodity.UpdatedTime = DateTime.Now;
                _commodity.Update(commodity);
                return JsonHelper.Serialize(new
                {
                    Code = 200,
                    Data = commodity,
                    Msg = string.Format("你修改商品的id为：{0}，已经修改成功，请注意查收", id)
                });
            }
            else
            {
                return JsonHelper.Serialize(new
                {
                    Code = 1004,
                    Data = "",
                    Msg = "指定Id的商品不存在，请确认后重试"
                });
            }
        }


    }
    
    
    }
